package zj.it.bhne.gridengineeringsurvey.myutils;

import android.app.Activity;
import android.app.ProgressDialog;

/**
 * Created by wzf on 2017/11/28.
 */
public class ProgressDialogUtil {
    private static ProgressDialogUtil mProgressDialogUtil;
    private ProgressDialog progressDialog;
    private Activity activity;

    public synchronized static ProgressDialogUtil getInstence() {
        if (mProgressDialogUtil == null) {
            mProgressDialogUtil = new ProgressDialogUtil();
        }
        return mProgressDialogUtil;
    }

    public void ProgressDialogShow(Activity activity, String title, String msg) {
        this.activity = activity;
        if (activity.isFinishing()) {
            return;
        }
        if (progressDialog == null) {
            progressDialog = new ProgressDialog(activity);
        }
        progressDialog.setTitle(title);
        progressDialog.setMessage(msg);
        progressDialog.setCanceledOnTouchOutside(false);
        if (!progressDialog.isShowing()) {
            progressDialog.show();
        }

    }

    public void ProgressDialogDismiss() {
        if (activity.isDestroyed() || activity.isFinishing()) {
        } else {
            if (progressDialog != null) {
                progressDialog.dismiss();
                progressDialog = null;
            }
        }
    }
}
